<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <a href="#/a">去a</a>
    <a href="#/b">去b</a>
    <div id="root"></div>
<script>
//每当hash值发生变化的时候，都会执行回调函数
let root = document.getElementById('root');
window.addEventListener('hashchange',()=>{
  let hash = window.location.hash;
  if(hash =='#/a'){
    root.innerHTML='<h1>a</h1>';
  }else if(hash =='#/b'){
    root.innerHTML='<h1>b</h1>';
  }
});
</script>    
</body>
</html>